/*
 * ConfiguracionTarifaFrm.java
 *
 * Created on 8 de mayo de 2006, 02:07 PM
 */

package inc.jmc.cyberboard.ztrashcan;

import inc.jmc.cyberboard.ui.*;
import java.text.FieldPosition;
import java.text.ParsePosition;
import javax.swing.*;
import inc.jmc.cyberboard.log.*;
import inc.jmc.cyberboard.*;
import inc.jmc.cyberboard.common.*;

import org.apache.log4j.Logger;


/**
 *
 * @author  vaiojmc
 */
public class ConfiguracionTarifaFrm extends javax.swing.JInternalFrame {
    
    static Logger logger = Logger.getLogger(ConfiguracionTarifaFrm.class.getName());
    
    public static final String error1="Error en los tipos de datos o faltan llenar campos";
    //PrecioHoraPane precioHoraPane1=new PrecioHoraPane();
    public static final int INCREMENTO_SCROLL=270;
    /**
     * Creates new form ConfiguracionTarifaFrm
     */
    public ConfiguracionTarifaFrm() {
        initComponents();
        this.setIconifiable(true);
        this.setSize(770,405);
        this.setVisible(true);
        this.setResizable(true);
        jTabbedPane1.setTitleAt(0,"Tarifa Cobro");
        this.setTitle("Configurar tarifa para renta de equipo");
        
        jScrollPane1.getVerticalScrollBar().setUnitIncrement(ConfiguracionTarifaFrm.INCREMENTO_SCROLL);
        tituloHoraCmb.setEditable(false);
        this.setFrameIcon(ImageLoader.images[ImageLoader.ICON_FRAME_MAIN]);
        this.updateUI();
        logger.info("las interfaces de "+javax.swing.UIManager.getSystemLookAndFeelClassName()+" son:");
        /*for(int i=0;i<com.sun.java.swing.plaf.windows.WindowsLookAndFeel.class.getInterfaces().length;++i)
            logger.info("interfaz:"+com.sun.java.swing.plaf.windows.WindowsLookAndFeel.class.getInterfaces()[i].getName());*/
        for(int i=0;i<javax.swing.JTable.class.getInterfaces().length;++i)
            logger.info("interfaz:"+javax.swing.JTable.class.getInterfaces()[i].getName());
        /*try {
        javax.swing.UIManager.setLookAndFeel(
                //"com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
                javax.swing.UIManager.getSystemLookAndFeelClassName()
                //javax.swing.UIManager.getCrossPlatformLookAndFeelClassName()
                //"org.jvnet.substance.SubstanceLookAndFeel"
                );
        } catch (Exception e) 
        {
            e.printStackTrace();
        }
        SwingUtilities.updateComponentTreeUI(this);*/
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel8 = new javax.swing.JPanel();
        jPanel9 = new javax.swing.JPanel();
        jPanel10 = new javax.swing.JPanel();
        agregaTarifaBtn = new javax.swing.JButton();
        tituloHoraCmb = new javax.swing.JComboBox();
        esquemaPagoCmb = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        aplicaTarifasButton = new javax.swing.JButton();
        jPanel11 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        panelDivideTiempo = new javax.swing.JPanel();
        jPanel12 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();

        setClosable(true);
        setTitle("Configurar tarifa para renta de equipo");
        setPreferredSize(new java.awt.Dimension(295, 187));
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                formComponentResized(evt);
            }
        });

        jPanel8.setLayout(new java.awt.BorderLayout());

        jPanel9.setLayout(new java.awt.BorderLayout());

        jPanel10.setLayout(null);

        jPanel10.setPreferredSize(new java.awt.Dimension(160, 100));
        agregaTarifaBtn.setText("Agregar>>");
        agregaTarifaBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                agregaTarifaBtnActionPerformed(evt);
            }
        });

        jPanel10.add(agregaTarifaBtn);
        agregaTarifaBtn.setBounds(10, 120, 110, 23);

        tituloHoraCmb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1a Hora", "El resto de las horas" }));
        jPanel10.add(tituloHoraCmb);
        tituloHoraCmb.setBounds(10, 90, 130, 22);

        esquemaPagoCmb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Division de horas" }));
        jPanel10.add(esquemaPagoCmb);
        esquemaPagoCmb.setBounds(10, 40, 130, 22);

        jLabel10.setText("Hora");
        jPanel10.add(jLabel10);
        jLabel10.setBounds(10, 70, 70, 14);

        jLabel11.setText("Esquema de pago");
        jPanel10.add(jLabel11);
        jLabel11.setBounds(10, 20, 110, 14);

        aplicaTarifasButton.setText("Aplicar");
        aplicaTarifasButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aplicaTarifasButtonActionPerformed(evt);
            }
        });

        jPanel10.add(aplicaTarifasButton);
        aplicaTarifasButton.setBounds(10, 220, 130, 23);

        jPanel9.add(jPanel10, java.awt.BorderLayout.WEST);

        jPanel11.setLayout(new java.awt.BorderLayout());

        panelDivideTiempo.setLayout(new java.awt.GridLayout(150, 0));

        panelDivideTiempo.addContainerListener(new java.awt.event.ContainerAdapter() {
            public void componentRemoved(java.awt.event.ContainerEvent evt) {
                panelDivideTiempoComponentRemoved(evt);
            }
        });

        jScrollPane1.setViewportView(panelDivideTiempo);

        jPanel11.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jPanel12.setLayout(null);

        jPanel12.setPreferredSize(new java.awt.Dimension(100, 10));
        jPanel11.add(jPanel12, java.awt.BorderLayout.SOUTH);

        jPanel9.add(jPanel11, java.awt.BorderLayout.CENTER);

        jPanel8.add(jPanel9, java.awt.BorderLayout.CENTER);

        jTabbedPane1.addTab("tab3", jPanel8);

        getContentPane().add(jTabbedPane1, java.awt.BorderLayout.CENTER);

        jPanel6.setLayout(new java.awt.BorderLayout());

        jPanel6.setPreferredSize(new java.awt.Dimension(100, 25));
        jLabel8.setText("Selecciona el criterio de cobro");
        jPanel6.add(jLabel8, java.awt.BorderLayout.CENTER);

        getContentPane().add(jPanel6, java.awt.BorderLayout.NORTH);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public void agregaTarifaBtnActionPerformed()
    {
        agregaTarifaBtnActionPerformed(null);
    }
    public void aplicaTarifasButtonActionPerformed() {                                            
        aplicaTarifasButtonActionPerformed(null);
    }
    
    private void agregaTarifaBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_agregaTarifaBtnActionPerformed
        String opci=(String)tituloHoraCmb.getSelectedItem();
        //antes de agregar el nuevo panel, ponemos el boton del ultimo panel existente como deshabilitado
        if(panelDivideTiempo.getComponentCount()>0) {
            PrecioHoraSegmentPane previus=(PrecioHoraSegmentPane)panelDivideTiempo.getComponent(panelDivideTiempo.getComponentCount()-1);
            //previus.getBorrarBtn().setEnabled(false);
        }
        //panelDivideTiempo.add(new PrecioHoraSegmentPane(opci));
        //panelDivideTiempo.repaint();
        panelDivideTiempo.updateUI();
        String opcitxt=""+(panelDivideTiempo.getComponentCount()+1)+"a Hora";
        tituloHoraCmb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { opcitxt }));
    }//GEN-LAST:event_agregaTarifaBtnActionPerformed

    private void aplicaTarifasButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aplicaTarifasButtonActionPerformed
        Tarifa.revemoAllTarifas();
        for(int i=0;i<panelDivideTiempo.getComponentCount();++i) {
            PrecioHoraSegmentPane panelPrecio=(PrecioHoraSegmentPane)panelDivideTiempo.getComponent(i);
            /*if(panelPrecio.getTarifa().getPreciosEnTabla()==null)
            {
                JOptionPane.showMessageDialog(this,"Algunos campos no se llenaron correctamente en la tarifa-","Verifique los datos proporcionados",JOptionPane.ERROR_MESSAGE);
                return;
            }
            
            Tarifa.addTarifaToCollection(panelPrecio.getTarifa());*/
        }
        JOptionPane.showMessageDialog(this,"Tarifa aplicada: "+jTabbedPane1.getTitleAt(jTabbedPane1.getSelectedIndex()),"Tarifa Aplicada",JOptionPane.INFORMATION_MESSAGE);
        logger.info("Todas las tarifas actualizadas");
        Tarifa.loggerHoras();
    }//GEN-LAST:event_aplicaTarifasButtonActionPerformed

    private void panelDivideTiempoComponentRemoved(java.awt.event.ContainerEvent evt) {//GEN-FIRST:event_panelDivideTiempoComponentRemoved
        String opcitxt=""+(panelDivideTiempo.getComponentCount()+1)+"a Hora";
        tituloHoraCmb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { opcitxt }));
    }//GEN-LAST:event_panelDivideTiempoComponentRemoved

    private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
        logger.info(this.getClass().getName()+":"+this.getSize().width+","+this.getSize().height+"    ");
    }//GEN-LAST:event_formComponentResized

    public JPanel getPanelDivideTiempo() {
        return panelDivideTiempo;
    }
    public void setPanelDivideTiempo(JPanel panelDivideTiempo) {
        this.panelDivideTiempo = panelDivideTiempo;
    }
    


    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton agregaTarifaBtn;
    private javax.swing.JButton aplicaTarifasButton;
    private javax.swing.JComboBox esquemaPagoCmb;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JPanel panelDivideTiempo;
    private javax.swing.JComboBox tituloHoraCmb;
    // End of variables declaration//GEN-END:variables
    
}
